import 'data/goods_entity.dart';

class ShopCart {
  ShopCart._internal();

  factory ShopCart() => _instance;

  static late final ShopCart _instance = ShopCart._internal();

  List<GoodsEntity> shopGoods = [];

  void addGoods(GoodsEntity good) {
    shopGoods.add(good);
  }

  void delGoods(GoodsEntity good) {
    shopGoods.remove(good);
  }

  void clear() {
    shopGoods.clear();
  }

  List<GoodsEntity> getGoods() {
    return shopGoods;
  }

  double getGoodsPrice() {
    return shopGoods.fold<double>(
        0, (previousValue, element) => previousValue + (element.price ?? 0));
  }
}
